<template>
  <q-page class="q-pa-md">
    <div class="q-pb-md text-h5">
      {{pageTitle}}
      <span class="text-subtitle1">{{$t('列表')}}</span>
    </div>
    <div class="shadow-2">
      <q-table v-model:pagination="paginationInfo" :columns="fpsInfo.columnsInfo" :hide-pagination="true"
        :loading="listDataLoadingState" :rows="$d.tableData"
        :visible-columns="fpsInfo.visibleColumns" binary-state-sort
        color="primary" dense flat row-key="roleId" separator="cell"
        @request="fpsAssist.onDataTableRequest" @row-dblclick="(evt,row)=>{fpsNav.gotoDetail(row.roleId)}">
        <template v-slot:top="props">
          <!--功能按钮-->
          <div class="btn">
            <q-btn v-if="fx.hasModifyRight('Comm.RoleRight.Edit')" color="primary" icon="add" :label="$t('新建')" no-caps
              @click="fx.router.push({ name: '/comm/cfg/roleright/create' })" />
          </div>
          <!--填充所有剩余空间-->
          <q-space />
          <q-btn dense icon="refresh" title="刷新" unelevated @click="loadListData" />
          <!--右上角列控制-->
          <table-col-options-cfg v-model:table-columns="fpsInfo.columnsInfo"
            v-model:visible-columns="fpsInfo.visibleColumns"
            class="q-ml-sm" @update-col-options-for-save="fpsAssist.saveColOptions"></table-col-options-cfg>
          <!--右上角全屏按钮-->
          <q-btn :icon="props.inFullscreen ? 'fullscreen_exit' : 'fullscreen'"
            :ripple="false" :title="props.inFullscreen ? $t('退出全屏') : $t('全屏显示')" class="q-ml-sm" dense flat
            @click="props.toggleFullscreen" />
        </template>
        <!--无数据提示-->
        <template v-slot:no-data>
          <span class="full-width text-center"> <q-icon name="error_outline" /> {{$t('无数据')}} </span>
        </template>
        <!--操作列插槽-->
        <template v-slot:body-cell-operation="props">
          <q-td :props="props" auto-width>
            <q-btn class="btn-in-row q-mr-xs" color="primary" dense :label="$t('查看')" no-caps
              @click="evt => fpsNav.gotoDetail(props.row.roleId, evt)" />
            <q-btn v-if="fx.hasModifyRight('Comm.RoleRight.Edit')" :dense="true"
              :disable="props.row.roleId === 1"
              class="btn-in-row" color="primary" :label="$t('编辑')" no-caps
              @click="evt =>  fpsNav.gotoEdit(props.row.roleId, evt)" />
          </q-td>
        </template>
      </q-table>
    </div>
  </q-page>
</template>

<script lang="ts">
export default {
  name: 'roleRightListStd'
}
</script>
<script lang="ts" setup>
import {useFpsHelper} from '../../hooks/fpsHelper'
import {useTitleHelper} from '../../hooks/titleHelper'
import {reactive, ref} from 'vue'
import {Role} from '../../defs/role'
import {ColumnInfo} from '../../defs/comm'
import { useI18n } from 'vue-i18n'
const {t} = useI18n()

const pageTitle = t('角色权限')
useTitleHelper(pageTitle)

// 分页参数
let paginationInfo = {
  page: 1,
  rowsPerPage: 0
}

// 列参数
const columnsDefine: ColumnInfo[] = [
  {
    name: 'operation',
    label: t('操作'),
    field: 'operation',
    align: 'left',
    defOrder: 1,
    defVisible: true
  },
  {
    name: 'roleId',
    label: t('角色ID'),
    align: 'left',
    field: 'roleId',
    defOrder: 2,
    defVisible: true
  },
  {
    name: 'roleName',
    label: t('角色名称'),
    field: 'roleName',
    align: 'left',
    defOrder: 3,
    defVisible: true
  },
  {
    name: 'descriptions',
    label: t('描述'),
    field: 'descriptions',
    align: 'left',
    defOrder: 4,
    defVisible: true
  }
]

const $d = reactive({
  tableData: [] as Role[]
})

// 是否处于数据列表加载的状态
let listDataLoadingState = ref(false)
const loadListData = function () {
  listDataLoadingState.value = true
  $f.axios.get<Role[]>('/comm/rr/get-all-roles')
    .then((result) => {
      fpsAssist.handleGenericFpsResp(result.data)
      $d.tableData = result.data
      //fpsAssist.saveFpsReq(fpsReq)
    })
    .catch((err) => {
      $f.ui.showNotifyFailed($f.getAxiosErrMsg(err))
    })
    .finally(() => {
      listDataLoadingState.value = false
    })
}

//region FPS配置
const {
  fpsInfo,
  fpsAssist,
  fpsNav
} = useFpsHelper('/comm/cfg/rolerightlist',
  '/comm/cfg/roleright/detail',
  '/comm/cfg/roleright/create',
  '/comm/cfg/roleright/edit',
  null, columnsDefine,
  null,
  loadListData)
//endregion

const fx = $f
</script>
